$(function(){
	oSaveFun();
	oDomTabFun();

	/*$('#submit').click(function(){
			var
				oUserId = $('input[name=userId]').val(),
				oNumber = $('input[name=number]').val(),
				oAddress = $('input[name=address]').val(),
				oPrice = $('input[name=price]').val(),
				oButtonPrice = $('input[name=buttonPrice]').val(),
				oBargainMin = $('input[name=bargainMin]').val(),
				oBargainMax = $('input[name=bargainMax]').val(),
				oBargainNumber = $('input[name=bargainNumber]').val();
		});*/
});
//点击保存按钮
function oSaveFun(){

	$('#submit').click(function(){
		var oData = {};
		var oInputs = $('.get-input input');
		oInputs.each(function(){
			var key = this.attributes['data-name'].value;
			//if(this.value !== ''){
			oData[key] = this.value;
			//}
		});

		oAjaxFun(oData);
	});
}

// 调用ajax
function oAjaxFun(data){
	var oData = [data];
	$.ajax({
		type:"post",
		url:"http://localhost/activity",
		data:oData,
		dataType : 'json',
		contentType : 'application/json',
		success:function(data){
			console.log(data);
		},
		error:function(err){
			console.log(err);
		}
	});
}

//点击切换
function oDomTabFun(){
	$('#cut').click(function(){
		$('.conts').eq(0).css('display','none');
		$('.conts').eq(1).css('display','block');
	});
	$('#return').click(function(){
		$('.conts').eq(0).css('display','block');
		$('.conts').eq(1).css('display','none');
	});
	$('.nav-tabs li').click(function(){
		var iIndex = $(this).index();
		$('.cut-lis li').removeClass('active').eq(iIndex).addClass('active');
		$('.panel-body').css('display','none').eq(iIndex).css('display','block');
	});
}
//  图片上传
/*
function uploadImg() {
	var config = $("body").data("config");
	var host = "http://192.168.59.2:7090/image";
	var firstName = "http://choosefine-uat.oss-cn-hangzhou.aliyuncs.com/";

	if ($('[data-pic]')) {
		$('[data-pic]')

			.html(`
            <img src="#">
            <form action=${host} method="post" enctype="multipart/form-data" target="hide_frame" style="display: none;">
              <input name="name">
              <input type="file" name="file"/>
            <form>
          `)

			.find('[type="file"]').on('change',
			function () {

				var lastName = "console/user/" + (new Date()).getTime() + '-' + this.files[0].name;

				$(this).prev().val(lastName);
				$(this).parent().submit();

				console.log(firstName + lastName);

				setTimeout(function () {
					$(this).parent().prev().attr('src', firstName + lastName);
				}.bind(this), 12000)

			});

		$('[data-pic]')

			.each(function (i, div) {
				var dataName = $(div).attr('data-pic');

				$(div).find('img').attr('data-name', dataName)
			});

		$('[data-pic]').find('img')
			.on('click', function () {
				$(this).parent().find('[type="file"]').click();
			})

		$(document.body).append(`
            <iframe name="hide_frame" style="display: none">
          `)
	}

	if ($("[data-purl]")) {
		var images = $("[data-purl]").find('img');
		var purl = "";

		images.each(function (i, img) {
			purl = $(img).parent().attr('data-purl');
			$(img).attr('src', purl);
		})
	}
}*/
